program inline_constraint;

class packet;
    rand bit [3:0] addr;
    rand bit [3:0] data;

    constraint data_range { data > 0;
                            data < 10; }
    // 约束求解器会同时考虑类约束和内联约束
    constraint addr_range { addr inside {[0:8]}; }
    // 类约束与内联约束之间的冲突会导致随机化失败
    // constraint addr_range { addr inside {5,10,15}; }
endclass

initial begin
    packet pkt;
    pkt = new();
    repeat(4) begin
        pkt.randomize() with { addr == 8;}; // inline constraint
        $display("\taddr = %0d data = %0d", pkt.addr, pkt.data);
    end
end

endprogram;
